home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
examples
/
insight
/
plugins
/
mybias.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
12KB
|
353 lines
; $Id: mybias.pro,v 1.15 1997/04/22 17:12:33 rob Exp $
;
; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;+
; FILE:
; mybias.pro
;
; PURPOSE:
; This file contains an example Analysis PlugIn that does biasing.
;
; CONTENTS:
; GENERAL ROUTINES
; pro HandleEventsMyBias - handle dialog box events
;
; CALLBACK ROUTINES
; fun ApplyMyBias - Apply/OK entry point
; fun PromptUserMyBias - main entry point (creates dialog)
;
; REGISTRATION FUNCTION
; fun MyBias - registers the PlugIn
;
;-
; *****************************************************************************
; GENERAL ROUTINES
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Handle dialog events.
;
pro HandleEventsMyBias, sEvent
; Widget state information.
;
common MyBiasCommon, psState
wGroup = (*psState).wMainBase
; Catch errors.
;
CATCH, error
if (error ne 0) then begin
CATCH, /CANCEL
void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=wGroup)
RETURN
endif
; ========================
; PROCESS EVENTS
; ========================
case (sEvent.id) of
; --------------------------------------
; Input text
; --------------------------------------
(*psState).wInputText: begin
; (nothing to do now)
end
; --------------------------------------
; Input browse button
; --------------------------------------
(*psState).wInputBrowseButton: begin
; Let user browser for a data name.
;
void = INSGET( $
NAME=inputName, $ ; returned name of data selected
/EXCLUSIVE, $ ; only one selection
TITLE='Select a vector.', $ ; title of browser
DIMS_LIST=1, $ ; show 1D data only
COUNT=count, $ ; returned count of items selected
GROUP=wGroup, $ ; wiget group leader
_EXTRA=(*psState).extra) ; extra information
; If user selected an item, set data name in text widget.
;
if (count eq 1) then $
WIDGET_CONTROL, (*psState).wInputText, SET_VALUE=inputName
end
; --------------------------------------
; Bias bgroup
; --------------------------------------
(*psState).wBiasBgroup: begin
WIDGET_CONTROL, (*psState).wBiasBgroup, GET_VALUE=value
if (value eq 0) then $
(*psState).biasMult = -1 $
else if (value eq 1) then $
(*psState).biasMult = 1 $
else $
(*psState).biasMult = 0
end
; --------------------------------------
; OK/Apply/Cancel buttons
; --------------------------------------
(*psState).wOKApplyCancelButtons: begin
; Destroy dialog on successful OK selection, or if user canceled.
;
if ((sEvent.type eq 'OK') or $
(sEvent.type eq 'Cancel')) then $
WIDGET_CONTROL, (*psState).wMainBase, /DESTROY
end
; --------------------------------------
; other events
; --------------------------------------
else: ; (do nothing)
endcase
end ; HandleEventsMyBias
; *****************************************************************************
; CALLBACK ROUTINES
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Get data and bias it (called when Apply or OK button hit).
; Fuction returns 1B on success, else 0B.
;
function ApplyMyBias, $
CIDs=CIDs, $ ; OUT: command ID list from INSPUT/INSVIS calls
DATA_NAME=dataName, $ ; IN: name of data selected in visualization window
_EXTRA=extra ; IN: information to pass to commands
; Widget state information.
;
common MyBiasCommon, psState
wGroup = (*psState).wMainBase
; ---------------------------------------------------------
; Catch errors.
; ---------------------------------------------------------
CATCH, error
if (error ne 0) then begin
CATCH, /CANCEL
void = DIALOG_MESSAGE(!ERR_STRING, DIALOG_PARENT=(*psState).wMainBase)
RETURN, 0B
endif
; ---------------------------------------------------------
; Check inputs.
; ---------------------------------------------------------
; Get and check input data name.
;
WIDGET_CONTROL, (*psState).wInputText, GET_VALUE=inputName
inputName = inputName[0]
if (inputName eq '') then $
MESSAGE, 'Must specify input data.'
; Get input data.
;
inputData = INSGET( $
inputName, $ ; name of data to get
PTR_OUT=0, $ ; return data, thus ASSOC data will work
COUNT=count, $ ; returned number of items found
DIMS_LIST=1, $ ; data should have this dimensionality
GROUP=wGroup, $ ; widget group leader
_EXTRA=extra) ; extra information
; Return if data not found (INSGET displays own error messages).
;
if (count ne 1) then $
RETURN, 0B
; ---------------------------------------------------------
; Perform biasing.
; ---------------------------------------------------------
minVal = MIN(inputData, MAX=maxVal)
bias = 0.3 * (maxVal - minVal)
bias = bias * (*psState).biasMult
newData = inputData + bias
; ---------------------------------------------------------
; Put the new data into Insight.
; ---------------------------------------------------------
description = 'Biased "' + inputName + '" by ' + $
STRING(STRCOMPRESS(bias, /REMOVE_ALL)) + '.'
outputName = (*psState).outputName
INSPUT, $
newData , $ ; the data
DESCRIPTION = description, $ ; data description
NAME = outputName, $ ; try this data name
NEW_NAME = outputNameUsed, $ ; the data name actually used
REPLACE = 2, $ ; prompt user if name conflict
COUNT = count, $ ; returned # of items put
CIDs = CIDs, $ ; command ID list
GROUP = wGroup, $ ; widget group leader
_EXTRA = extra ; extra information
; Return if "put" failed.
;
if (count ne 1) then $
RETURN, 0B
; ---------------------------------------------------------
; Visualize new data item.
; ---------------------------------------------------------
INSVIS, $
outputNameUsed, $ ; name of data item
TYPE = 'plot', $ ; visualization type
MODE = 'new', $ ; insert | new | overlay
CIDs = CIDs, $ ; command ID list
GROUP = wGroup, $ ; widget group leader
_EXTRA = extra ; extra information
; ---------------------------------------------------------
; Successful return.
; ---------------------------------------------------------
RETURN, 1B
end ; ApplyMyBias
; -----------------------------------------------------------------------------
;
; Purpose: Main entry point for the PlugIn.
;
pro PromptUserMyBias, $
GROUP=wGroup, $ ; IN: group leader widget ID
DATA_NAME=dataName, $ ; IN: name of data selected in visualization window
_EXTRA=extra ; IN: various information
; Widget state information.
;
common MyBiasCommon, psState
; Create modal main base (non-sizable).
;
title = 'Analysis PlugIn Example - My Bias'
wMainBase = WIDGET_BASE(TITLE=title, GROUP_LEADER=wGroup, $
/COLUMN, /MODAL, /TLB_FRAME_ATTR)
value = [ $
'Select vector (1D) data to plot with', $
'negative, positive, or no 30% bias.' $
]
for i = 0, N_ELEMENTS(value)-1 do $
void = WIDGET_LABEL(wMainBase, VALUE=value[i])
; ------------------------------------------
; Create INPUTS widgets.
; ------------------------------------------
wInputsBase = WIDGET_BASE(wMainBase, /COLUMN, /FRAME)
void = WIDGET_LABEL(wInputsBase, VALUE='INPUTS')
wInputDataBase = WIDGET_BASE(wInputsBase, /ROW)
void = WIDGET_LABEL(wInputDataBase, VALUE='Input: ')
wInputText = WIDGET_TEXT(wInputDataBase, VALUE=dataName, /EDITABLE)
wInputBrowseButton = WIDGET_BUTTON(wInputDataBase, VALUE=' Browse... ')
wBiasBase = WIDGET_BASE(wInputsBase, /ROW)
void = WIDGET_LABEL(wBiasBase, VALUE='Bias: ')
wBiasBgroup = CW_BGROUP(wBiasBase, ['Negative', 'Positive', 'None'], $
/NO_RELEASE, /ROW, /RETURN_NAME, /EXCLUSIVE, SET_VALUE=1)
biasMult = 1
; ------------------------------------------
; Create OUTPUTS widgets.
; ------------------------------------------
outputName = 'Bias Output'
wOutputsBase = WIDGET_BASE(wMainBase, /ROW, /FRAME)
void = WIDGET_LABEL(wOutputsBase, VALUE=' ')
wOutputsLabelBase = WIDGET_BASE(wOutputsBase, /COLUMN)
void = WIDGET_LABEL(wOutputsLabelBase, VALUE='OUTPUTS')
void = WIDGET_LABEL(wOutputsLabelBase, VALUE='Output: '+outputName)
; ------------------------------------------
; Create OK/Apply/Cancel buttons using special compound widget.
; (Must pass in main modal base, used to set default and cancel buttons.)
;
wOKApplyCancelButtons = CW_INSAPPLY(wMainBase, _EXTRA=extra)
; Create dialog state information.
;
sState = { $
extra: extra, $
wMainBase: wMainBase, $
outputName: outputName, $
wInputText: wInputText, $
wInputBrowseButton: wInputBrowseButton, $
wBiasBgroup: wBiasBgroup, $
biasMult: biasMult, $
wOKApplyCancelButtons: wOKApplyCancelButtons $
}
; Store the state in a heap variable.
;
psState = PTR_NEW(sState, /NO_COPY)
; Realize the dialog box.
;
WIDGET_CONTROL, wMainBase, /REALIZE
; Start event loop.
;
XMANAGER, 'PromptUserMyBias', wMainBase, EVENT_HANDLER='HandleEventsMyBias'
; Remove widget state info.
;
PTR_FREE, psState
end ; PromptUserMyBias
; *****************************************************************************
; REGISTRATION FUNCTION
; *****************************************************************************
; -----------------------------------------------------------------------------
;
; Purpose: Register the Analysis PlugIn.
;
function MyBias
; Return the Analysis PlugIn Registration Structure.
;
RETURN, { $
type: 'Analysis_PlugIn', $ ; PlugIn type
title: 'My Bias...', $ ; PlugIn title
purpose: 'Do simple biasing.', $ ; PlugIn purpose
main_proc: 'PromptUserMyBias', $ ; main callback
apply_func: 'ApplyMyBias', $ ; apply callback
version: '5.0', $ ; IDL version
revision: '1.0' $ ; PlugIn version
}
end ; MyBias
; -----------------------------------------------------------------------------